package com.atguigu.gulimall.ware.service.impl;

import com.atguigu.common.exception.RRException;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.atguigu.gulimall.ware.dao.TestWareMapper;
import com.atguigu.gulimall.ware.entity.TestWare;
import com.atguigu.gulimall.ware.service.TestWareService;
@Service("TestWareService")
public class TestWareServiceImpl implements TestWareService{

    @Resource
    private TestWareMapper testWareMapper;

    @Override
    public int insert(TestWare record) {
        return testWareMapper.insert(record);
    }

    @Override
    public int updateByPrimaryKey(TestWare record) {
        Integer residue;
        TestWare testWare = testWareMapper.selectById(record.getId());
        if((residue = testWare.getTotal() - record.getUse())<0)
            throw new RRException("仓库库存不足");
        testWare.setResidue(residue);
        testWare.setUse(record.getUse());
        return testWareMapper.updateByPrimaryKey(testWare);
    }

}
